#ifndef WEB_H
#define WEB_H
#include <microhttpd.h>
#include "conf.h"
#include "info.h"

/* Port of binding */
#define PORT 8013

/* Size of array */
#define LENGTH_OF_HASH 64+1
#define LENGTH_OF_UID 32

//--------------------------------------------------
/* file paths */
#define CONF_PATH		"./data/conf.txt"

#define STATIC_FAVICON_ICO	"./html/favicon.ico"
#define STATIC_LOGIN_HTML	"./html/login.html"
#define STATIC_LOGIN_CSS	"./html/login.css"
#define STATIC_LOGIN_JS		"./html/login.js"
#define STATIC_INDEX_HTML	"./html/index.html"
#define STATIC_INDEX_CSS	"./html/index.css"
#define STATIC_INDEX_JS		"./html/index.js"
#define STATIC_LOGO_JPG		"./html/logo.jpg"

#define STATIC_GLOBAL_CSS	"./html/global.css"

//--------------------------------------------------

/* 用于初始化连接信息 */
void InitInfo(struct Information* info);
//--------------------------------------------------
/* 保存 json 格式文件配置 */
int save_json_conf(char *filename);
/* 读取 json 格式文件配置 */
int read_json_conf(char *filename, struct DatabaseKeygen *dk);
/* 释放 json 中读取的配置 */
void release_json_conf(struct DatabaseKeygen *dk);
//--------------------------------------------------
/* 使用 sha256 加密字符串，注意 output 容量需大于 64 */
void sha256(const char *input, char *output);
//--------------------------------------------------
/* 传送至 libmircrohttpd 处理响应的回调函数 */
enum MHD_Result answer_to_connection(void *cls,
				struct MHD_Connection *connection,
				const char *url,
				const char *method,
				const char *version,
				const char *upload_data,
				unsigned long *upload_data_size,
				void **con_cls);
/* 用于 libmicrohttpd 中遍历参数的回调 */
enum MHD_Result my_iterator(void *cls, enum MHD_ValueKind kind, const char *key, const char *value);
/* 用于 libmicrohttpd 中读取文件并发送的回调 */
ssize_t ahc_read_from_file(void *cls, uint64_t pos, char *buf, size_t max);
/* 用于 libmicrohttpd 中关闭资源的回调 */
void free_file(void *cls);
//--------------------------------------------------
/* 从 User 表中查找目标用户 */
int Query_from_User(struct DatabaseKeygen *dk, char *username, char *hash);
/* 向 User 表中插入用户记录 */
int Insert_to_User(struct DatabaseKeygen *dk, char *username, char *hash);

#endif
